// FilePlugins.h

#ifndef __FILEPLUGINS_H
#define __FILEPLUGINS_H

#include "../Registry/RegistryPlugins.h"
#include "../Registry/RegistryAssociations.h"

#include <vector>

namespace Common {
namespace Plugin {

struct CPluginEnabledPair
{
  int	Index;
  BOOL	Enabled;
  CPluginEnabledPair(int index, bool enabled): Index(index),Enabled(enabled) {}
  CPluginEnabledPair(const CPluginEnabledPair & obj) :
	  Index(obj.Index),
	  Enabled(obj.Enabled)
  {
  }
  CPluginEnabledPair & operator= (const CPluginEnabledPair & obj)
  {
	  Index = obj.Index;
	  Enabled = obj.Enabled;
	  return *this;
  }
};

struct CExtInfoBig
{
  CString Ext;
  BOOL Associated;
  std::vector<CPluginEnabledPair> PluginsPairs;
  int FindPlugin(int pluginIndex)
  {
    for (size_t i = 0; i < PluginsPairs.size(); i++)
      if (PluginsPairs[i].Index == pluginIndex)
        return i;
    return -1;
  }
};

class CExtDatabase
{
public:
	std::vector<std::shared_ptr<CExtInfoBig> > ExtBigItems;
	std::vector<std::shared_ptr<Registry::CPluginInfo> > Plugins;
  int FindExtInfoBig(const CString &ext);
  int FindPlugin(const CString &plugin);

  CString GetMainPluginNameForExtItem(int extIndex) const
  {
    const auto &extInfo = ExtBigItems[extIndex];
    if (extInfo->PluginsPairs.empty())
      return CString();
    else
      return Plugins[extInfo->PluginsPairs.front().Index]->Name;
  }

  void Read();
  void Save();
};

}}


#endif


